<?php
/**
 * Created by PhpStorm.
 * User: Talent Gao
 * Date: 14-8-19
 * Time: 下午1:43
 */


class IndexController extends Controller {

    private $_title;
    private $_keywords;
    private $_description;

    public function init() {
        parent::init();
        // 取得用户信息
        $user_info = $this->_session->offsetGet ( 'loginInfos' );
        $this->_view->userInfo=$user_info;
    }

    public function indexAction(){
        global $_getAreaNames,$_saleOrderType,$_SupplyOrderCfg,$_suppliyStateCfg,$_suppliyStateMean,$_PurchaseOrderMean,$_BuyStartMean,$_BuyStateCfg;//头部信息
        define('ITEM_PER_PAGE', 10);
        $this->_title = '首页';
        $this->_keywords = '首页-塑料交易-买塑料放心';
        $this->_description = '首页';
        $kd= $this->_request->getParam('kd');
        $kd=empty($kd) ? '' :htmlspecialchars(trim($kd) , ENT_QUOTES ,'utf-8');
        //分类
        $index = new IndexModel();
        $cate = $index->getCateInfo("cate",'','');//第一个参数是产品的分类，第二个参数是根据分类查询的产品，第三个参数是根据产品查询的报价数，w问题：当不填写数量时，查询所有，速度会变慢
        //原油指数
        $IndexMark = $index->getIndexMark("IndexMark");
        //1F 自营现货 $HomeData['f1_index']
        $HomeData = $index->getHomeData();
//        var_dump($HomeData);
        //F1交易动态
        $tradewhere = " so.status <> {$_SupplyOrderCfg['cancel']}";
        $tradeorder =  $index->getTradeWhereType($tradewhere,$limit="0,10");
        //F2最新求购
        $inquirewhere = "iq.status not in ({$_BuyStateCfg['wait_audit']},{$_BuyStateCfg['cancel']})";
        $inquireorder =  $index->getInquireWhereStatus($inquirewhere,$limit="0,10");
        //F3最新供应
        $Supplywhere = "iq.status in ({$_suppliyStateCfg['up']})";
        $Supplyorder =  $index->getSupplyWhereStatus($Supplywhere,$limit="0,10");
        //供应商发布排行
        $RankingWhere = "1=1";
        $Rankingorder = "visit desc";
        $RankingBusiness =  $index->getRankingWhereVisit($RankingWhere,$Rankingorder,$limit="0,10");
        //新闻公告
        $newswhere = "1=1 and index_show = 'Y'";
        $news  = $index->getNewsInfo($newswhere,$limit="0,2");
        //这边截取标题的长度
        if(!empty($news)){
            foreach($news as $key=>$val){
                if(!empty($val['list'])){
                    foreach($val['list'] as $k=>$v){
                        $news[$key]['list'][$k]['title'] = Tools::substr($v['title'],0,12,"utf-8")."...";
                        $news[$key]['list'][$k]['release_time'] = Tools::substr($v['release_time'],0,10,"utf-8");
                    }
                }
            }
        }

        //这边添加首页的轮播
        $carousel = $index->getCarousel("c.index_show = 'Y' and a.index_show = 'Y'");


        $this->_view->title = $this->_title;
        $this->_view->keywords  = $this->_keywords;
        $this->_view->description = $this->_description;
        $this->_view->_getAreaNames = $_getAreaNames;
        $this->_view->cate = $cate;
        $this->_view->IndexMark = $IndexMark;
        $this->_view->HomeData = $HomeData;
        $this->_view->tradeorder = $tradeorder;
        $this->_view->_PurchaseOrderMean = $_PurchaseOrderMean;
        $this->_view->inquireorder = $inquireorder;
        $this->_view->_BuyStartMean = $_BuyStartMean;
        $this->_view->Supplyorder = $Supplyorder;
        $this->_view->_suppliyStateMean = $_suppliyStateMean;
        $this->_view->RankingBusiness = $RankingBusiness;
        $this->_view->news = $news;
        $this->_view->kd = $kd;
        $this->_view->carousel = $carousel;
        $this->_view->image_url = IMAGE_URL_ADMIN;
    }


    public function testAction(){
        $config = Yaf_Application::app()->getConfig();
        $arr = $config->MobileCaptcha->toArray();
        var_dump($arr);die();
//        $s  = Sms::checkBlance(1);
//        die($s);
//        echo "---test()------";
//        $code = Tools::getRandNums(6);
//        $data = array(
//            'code' => $code,
//            'mobile' => "18896525561",
//            'content' => "您好！短信测试！",
//        );
//        $dataType = "Register";
//        $sms_id = Sms::send("18896525561",$data,2,$dataType);
//        die($sms_id);
    }
}